package com.hkfg.dao;

import com.hkfg.domain.Blog;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface BlogDao {

    /**
     * 通过用户id查找所有的blog
     * @param userId
     * @return
     */
    @Select("select * from blog where user_id = #{user_id};")
    List<Blog> selectBlogById(int userId);

    /**
     * 新建一篇博客
     * @param blog
     * @return
     */
    @Insert("insert into blog(id, title, content, createtime, updatetime, user_id) values (null, #{title}, #{content}, NOW(), Now(), #{userId});")
    int buildBlog(Blog blog);

    /**
     * 根据id查找blog
     * @param id
     * @return
     */
    @Select("select * from blog where id = #{id};")
    Blog getBLogById(int id);

    /**
     * 根据id删除blog
     * @param id
     * @return
     */
    @Delete("delete from blog where id = #{id}")
    int deleteBlogById(int id);

    /**
     * 修改blog
     * @param id
     * @param title
     * @param content
     * @return
     */
    @Update("update blog set title = #{title}, content = #{content}, updatetime = NOW() where id = #{id};")
    int modifyBlog( @Param("id") int id, @Param("title") String title,  @Param("content") String content);

}
